﻿<?php
  error_reporting(0);
  session_start();
  $conn=mysql_connect('localhost','root','root');
  mysql_select_db('itxmgl',$conn);
  define(ALL_PS,"PHP");
  mysql_query("set names 'utf8'");
  
  $jsonData= json_encode($_POST); 
  $objData=json_decode($jsonData);
  $amount=$objData->{'purchase_number'}; 
  $keyword=$objData->{'goods_img_src'};   
 // $keyword='./src/commodity/145067782529399.jpeg';
  $keyword1=str_replace("./src/commodity/","","$keyword");
  $sql_show="SELECT * FROM `r_commodity` WHERE img1='$keyword1' ";
  $query_show=mysql_query($sql_show);
  $result=mysql_fetch_array($query_show);
  $username=$_SESSION["username"];
  $sq = "insert into r_shoppingcar(username,Course_Name,Price,Amount,img1)values
  ('$username','$result[Course_Name]','$result[Price]','$amount','$result[img1]')"; 
  mysql_query($sq);
  
  $sql="SELECT * FROM `r_shoppingcar` WHERE username='$username' ";
  $query=mysql_query($sql);
  while($result=mysql_fetch_array($query))
  {
     $arrayobject = new ArrayObject($result);
     $array[] =  $arrayobject;
  }
  $tempArr = array('objectArray'=>$array,'img_folder'=>'./src/commodity/');
  $backData = json_encode($tempArr); 
  echo $backData; 
  
  

?>